package com.ga.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;

public class Common extends Controller{
	
	public static String contextClassPath=Thread.currentThread().getContextClassLoader().getResource("").getPath();
	
	public static String usercase(){
		return " (case active when 1 then '已激活' else '未激活' end) activeText,"
				+ "(case sex when 1 then '男' when 2 then '女' else '保密' end) sexText ,"
				+ "(case channel when 1 then '第三方' else '站点' end) channelText ";
	}
	public static String videocase(){
		return "(case v.status when 1 then '审核中' when 2 then '通过' when 3 then '已发布' else '不通过' end) statusText ";
	}
	public static String replycase(){
		return "(case r.status when 1 then '审核中' when 2 then '通过' else '不通过' end) statusText ";
	}
	public static Map<String,Object> wheres(Map<String,Object> paraMap){
		Map<String,Object> map=new HashMap<String,Object>();
		
		Iterator<String> ite=paraMap.keySet().iterator();
		String wheres="";
		List<String> list=new ArrayList<String>();
		while(ite.hasNext()) {
			String k=(String)ite.next();
			String v=paraMap.get(k)==null?"":paraMap.get(k).toString();
			if(k.indexOf("time1")>0){
				wheres+=k.replace("1", "")+" >= ? and ";
				v=v.equals("")?"1111-01-01 00:00:01":v;
				list.add(v);
			}else if(k.indexOf("time2")>0){
				wheres+=k.replace("2", "")+" <= ? and ";
				v=v.equals("")?"9999-12-31 12::59:59":v;
				list.add(v);
			}
			else if(!"".equals(v)){
				if(k.lastIndexOf(">")>0){
					wheres+=k+" ? and ";
					list.add(v);
				}else if(k.lastIndexOf("=")>0){
					wheres+=k+" ? and ";
					list.add(v);
				}else{
					wheres+=k+" like ? and ";
					list.add("%"+v+"%");
				}
			}
		}
		Object[] param=new Object[list.size()];
		for (int j = 0; j < list.size(); j++) {
			param[j]=list.get(j);
		}
		wheres=wheres.substring(0,wheres.lastIndexOf("and "));
		map.put("wheres", wheres);
		map.put("param", param);
		return map;
	}
}
